/**
 * Copyright (C) T-Systems International, 2013-2014
 *
 * The copyright of the computer program herein is the property of
 * T-Systems International. The program may be used and/or copied
 * only with the written permission of T-Systems International or in
 * accordance with the terms and conditions stipulated in the
 * agreement/contract under which the program has been supplied.
 *
 * $Author$
 * $Date$
 * $Rev$
 */
package com.tsystems.migdb;

import com.google.common.collect.ImmutableMap;
import lombok.NonNull;
import org.quartz.*;
import org.quartz.spi.JobFactory;
import org.quartz.spi.TriggerFiredBundle;

import java.util.Map;

public class MigdbBeanJobFactory implements JobFactory {

    private final Map<JobKey, Job> keyToJobMap;

    /**
     * Constructs a MigdbBeanJobFactory instance.
     *
     * @param keyToJobMap key to job map, neither null keys nor null values are permitted
     * @throws NullPointerException if keyToJobMap:
     *                              * is null
     *                              * contains null keys and/or null values
     */
    public MigdbBeanJobFactory(@NonNull Map<JobKey, Job> keyToJobMap) {
        this.keyToJobMap = ImmutableMap.copyOf(keyToJobMap);
    }

    @Override
    public Job newJob(@NonNull TriggerFiredBundle bundle, @NonNull Scheduler scheduler) throws SchedulerException {
        return keyToJobMap.get(bundle.getJobDetail().getKey());
    }

}